//
//  ShopViewController.m
//  GouWoAi
//
//  Created by 赵佟越 on 16/5/5.
//  Copyright © 2016年 zhaotongyue. All rights reserved.
//

#import "ShopViewController.h"
#import "ShopCollectionViewCell.h"

@interface ShopViewController ()<UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate>

@property(nonatomic, strong)UIImageView *topImageViewPhoto;

@property(nonatomic, strong)UIImageView *topImageViewLaba;

@property(nonatomic, strong)UIImageView *topImageViewJianTou;

@property(nonatomic, strong)UILabel *topLableTitle;

@property(nonatomic, strong)UILabel *topLableDetail;

@property(nonatomic, strong)UIView *topView;

@property(nonatomic, strong)UIButton *allButton;

@property(nonatomic, strong)UIButton *ShopManagerButton;

@property(nonatomic, strong)UIButton *ShopDetailButton;

@property(nonatomic, strong)UIScrollView *scrollViewTop;

@property(nonatomic, strong)UIScrollView *scrollViewBack;

@property(nonatomic, strong)UITableView *mytableView;

@property(nonatomic, strong)NSArray *allListArr;

@property(nonatomic, strong)UIView *collectionBackView;

@property(nonatomic, strong)UIButton *priceBtn;

@property(nonatomic, strong)UIButton *XiaoLiangBtn;

@property(nonatomic, strong)UIButton *ShaiXuanBtn;

@property(nonatomic, strong)UICollectionView *myCollectionView;

@property(nonatomic, strong)UICollectionViewFlowLayout *layout;

@property(nonatomic, strong)UIImageView *shaiXuanImageView;

@property(nonatomic, assign)NSInteger canChangenum;

@property(nonatomic, assign)BOOL xiaoliangPaiXuBOOL;

@property(nonatomic, assign)BOOL jiagePaiXuliangBOOL;

@end

@implementation ShopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self layoutNavigationBar];
    [self makeBaseUI];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated{
    //    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.scrollViewTop.contentOffset = CGPointMake(-self.scrollViewBack.contentOffset.x/3, 0);
    
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

#pragma mark - Private Methods
- (void)layoutNavigationBar {
    self.view.backgroundColor = [UIColor getColorFromRGBString:@"#F2F2F2"];
    if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
        NSArray *list=self.navigationController.navigationBar.subviews;
        for (id obj in list) {
            if ([obj isKindOfClass:[UIImageView class]]) {
                UIImageView *imageView=(UIImageView *)obj;
                NSArray *list2=imageView.subviews;
                for (id obj2 in list2) {
                    if ([obj2 isKindOfClass:[UIImageView class]]) {
                        UIImageView *imageView2=(UIImageView *)obj2;
                        imageView2.hidden=YES;
                    }
                }
            }
        }
    }
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor getColorFromRGBString:@"#F48000"];
    self.title = @"便利店";
    self.view.backgroundColor = [UIColor getColorFromRGBString:@"#F2F2F2"];
    
    UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 18, 18)];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:17];
    [rightButton setImage:[UIImage imageNamed:@"sysicon_n_12"] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(rightButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
    
    UIButton *leftButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 18)];
    leftButton.titleLabel.font = [UIFont systemFontOfSize:17];
    [leftButton setImage:[UIImage imageNamed:@"sysicon_n_13"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(leftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
}

- (void)makeBaseUI{
    [self.view addSubview:self.topView];
    [self.view addSubview:self.allButton];
    [self.view addSubview:self.ShopManagerButton];
    [self.view addSubview:self.ShopDetailButton];
    [self.view addSubview:self.scrollViewBack];
    [self.view addSubview:self.scrollViewTop];
    [self.scrollViewBack addSubview:self.mytableView];
    [self.scrollViewBack addSubview:self.collectionBackView];
    [self.scrollViewBack addSubview:self.XiaoLiangBtn];
    [self.scrollViewBack addSubview:self.ShaiXuanBtn];
    [self.collectionBackView addSubview:self.priceBtn];
    [self.collectionBackView addSubview:self.myCollectionView];
    [self.topView addSubview:self.topImageViewJianTou];
    [self.topView addSubview:self.topImageViewLaba];
    [self.topView addSubview:self.topImageViewPhoto];
    [self.topView addSubview:self.topLableDetail];
    [self.topView addSubview:self.topLableTitle];
    [self.scrollViewBack addSubview:self.shaiXuanImageView];
    /**
     *  canChangenum = 1 销量排序可变
     *  canChangenum = 2 价格排序可变
     *  else 都不可变
     */
    self.canChangenum = 1;
    self.xiaoliangPaiXuBOOL = YES;
    self.jiagePaiXuliangBOOL = YES;
    
    UIView *TopLine = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ZTY_SCREEN_WIDTH/3, 3)];
    TopLine.backgroundColor = [UIColor getColorFromRGBString:@"F48000"];
    [self.scrollViewTop addSubview:TopLine];
    
    
    [self.collectionBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.allButton.mas_bottom).offset(5);
        make.bottom.equalTo(self.view.mas_bottom).offset(-55);
        make.left.mas_equalTo(ZTY_SCREEN_WIDTH/3 + 4);
        make.width.mas_equalTo(ZTY_SCREEN_WIDTH/3 * 2 - 4);
//        make.size.mas_equalTo(CGSizeMake(ZTY_SCREEN_WIDTH/3 * 2 - 4, ZTY_SCREEN_HEIGHT - 64 - 49 - 40 - 5));
    }];
    
    [self.mytableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.allButton.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(ZTY_SCREEN_WIDTH/3, ZTY_SCREEN_HEIGHT - 64 - 69  - 40 - 55));
    }];
    
    [self.scrollViewTop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.allButton.mas_bottom).offset(-2);
        make.size.mas_equalTo(CGSizeMake(ZTY_SCREEN_WIDTH, 2));
    }];
    
    [self.scrollViewBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.allButton.mas_bottom);
        make.size.mas_equalTo(CGSizeMake(ZTY_SCREEN_WIDTH, ZTY_SCREEN_HEIGHT - 64 - 49 - 40));
    }];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(0);
        make.size.mas_equalTo(CGSizeMake(ZTY_SCREEN_WIDTH, 55));
    }];
    
    [self.allButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom);
        make.left.equalTo(self.topView);
        make.size.mas_equalTo(CGSizeMake(ZTY_SCREEN_WIDTH/3, 55));
    }];
    
    [self.ShopManagerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom);
        make.left.equalTo(self.topView).offset(ZTY_SCREEN_WIDTH/3);
        make.size.mas_equalTo(CGSizeMake(ZTY_SCREEN_WIDTH/3, 55));
    }];
    
    [self.ShopDetailButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom);
        make.left.equalTo(self.topView).offset(ZTY_SCREEN_WIDTH/3 * 2);
        make.size.mas_equalTo(CGSizeMake(ZTY_SCREEN_WIDTH/3, 55));
    }];
    
    [self.priceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collectionBackView);
        make.left.equalTo(self.collectionBackView).offset((ZTY_SCREEN_WIDTH/3 * 2 - 4)/4);
        make.size.mas_equalTo(CGSizeMake((ZTY_SCREEN_WIDTH/3 * 2 - 4)/4, 25));
        
    }];
    
    [self.XiaoLiangBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collectionBackView);
        make.left.equalTo(self.collectionBackView).offset((ZTY_SCREEN_WIDTH/3 * 2 - 4)/4 * 2);
        make.size.mas_equalTo(CGSizeMake((ZTY_SCREEN_WIDTH/3 * 2 - 4)/4, 25));
    }];
    
    [self.ShaiXuanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collectionBackView);
        make.left.equalTo(self.collectionBackView).offset((ZTY_SCREEN_WIDTH/3 * 2 - 4)/4 * 3);
        make.size.mas_equalTo(CGSizeMake((ZTY_SCREEN_WIDTH/3 * 2 - 4)/4, 25));
    }];
    
    [self.myCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.priceBtn.mas_bottom).offset(3);
        make.left.equalTo(self.collectionBackView);
        make.size.mas_equalTo(CGSizeMake(ZTY_SCREEN_WIDTH/3 * 2 - 4, ZTY_SCREEN_HEIGHT - 64 - 49 - 40 - 5 - 40 - 55));
    }];

    [self.topImageViewPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(13);
        make.size.mas_equalTo(CGSizeMake(43, 43));
    }];
    
    [self.topLableTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topImageViewPhoto);
        make.left.equalTo(self.topImageViewPhoto.mas_right).offset(10);
        make.width.equalTo(self.view).offset(- 80);
    }];
    

    [self.topLableDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topLableTitle.mas_bottom).offset(10);
        make.left.equalTo(self.topImageViewPhoto.mas_right).offset(10);
        make.width.equalTo(self.view).offset(- 80);
    }];
    
    [self.topImageViewJianTou mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view).offset(13);
        make.size.mas_equalTo(CGSizeMake(13, 13));
    }];
    
    [self.shaiXuanImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.priceBtn.mas_left).offset(- 30 * _ZTY_SCREEN_WIDTH);
        make.centerY.equalTo(self.priceBtn);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    
    UIImageView *labaImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sysicon_n_15"]];
    [self.topView addSubview:labaImageView];
    [labaImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topLableDetail);
        make.left.equalTo(self.topLableDetail).offset(5);
        make.size.mas_equalTo(CGSizeMake(12, 12));
    }];
    
    
    UIButton *jiantouBtn = [[UIButton alloc]init];
    [jiantouBtn setImage:[UIImage imageNamed:@"rightJiantou"] forState:UIControlStateNormal];
    [jiantouBtn addTarget:self action:@selector(jiantouBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.topView addSubview:jiantouBtn];
    [jiantouBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topLableDetail);
        make.right.equalTo(self.topLableDetail).offset(- 10);
        make.size.mas_equalTo(CGSizeMake(6, 12));
    }];
    
    [self.priceBtn.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.priceBtn.mas_right).offset(-10);
        make.centerY.equalTo(self.priceBtn);
        make.size.mas_equalTo(CGSizeMake(7, 10));
    }];
    
    [self.priceBtn.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.priceBtn.mas_right).offset(-20);
        make.centerY.equalTo(self.priceBtn);
        make.size.mas_equalTo(CGSizeMake(26, 13));
    }];
    
    [self.XiaoLiangBtn.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.XiaoLiangBtn.mas_right).offset(-10);
        make.centerY.equalTo(self.priceBtn);
        make.size.mas_equalTo(CGSizeMake(7, 10));
    }];
    
    [self.XiaoLiangBtn.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.XiaoLiangBtn.mas_right).offset(-20);
        make.centerY.equalTo(self.priceBtn);
        make.size.mas_equalTo(CGSizeMake(26, 13));
    }];
    
    
    
    
}

#pragma mark - ScrollView Delegate And DataSource

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.scrollViewTop.contentOffset = CGPointMake(-self.scrollViewBack.contentOffset.x/3, 0);
    if (self.scrollViewBack.contentOffset.x == 0) {
        [self.allButton setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
        [self.ShopDetailButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
        [self.ShopManagerButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    }
    
    if (self.scrollViewBack.contentOffset.x == ZTY_SCREEN_WIDTH) {
        [self.allButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
        [self.ShopDetailButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
        [self.ShopManagerButton setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
    }
    
    if (self.scrollViewBack.contentOffset.x == ZTY_SCREEN_WIDTH * 2) {
        [self.allButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
        [self.ShopDetailButton setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
        [self.ShopManagerButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    }
}





#pragma mark - Button Action

- (void)rightButtonAction:(UIButton *)sender{
    // 搜索按钮
}

- (void)leftButtonAction:(UIButton *)sender{
    // 聊天按钮
}

- (void)jiantouBtnAction:(UIButton *)sender{
    // 喇叭按钮
}

- (void)ShaiXuanBtnAction:(UIButton *)sender{
    //筛选
    [self.ShaiXuanBtn setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
    [self.XiaoLiangBtn setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    [self.priceBtn setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    self.canChangenum = 0;
}

- (void)XiaoLiangBtnAction:(UIButton *)sender{
    // 销量排序
    [self.ShaiXuanBtn setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    [self.XiaoLiangBtn setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
    [self.priceBtn setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    [self.priceBtn setImage:[UIImage imageNamed:@"sysicon_n_18"] forState:UIControlStateNormal];
    if (self.canChangenum == 1) {
        if (self.xiaoliangPaiXuBOOL == YES) {
            // 销量递减
            [self.XiaoLiangBtn setImage:[UIImage imageNamed:@"changeXia"] forState:UIControlStateNormal];
            self.xiaoliangPaiXuBOOL = NO;
        }else{
            // 销量递增
            [self.XiaoLiangBtn setImage:[UIImage imageNamed:@"sysicon_n_17"] forState:UIControlStateNormal];
            self.xiaoliangPaiXuBOOL = YES;
        }
    }else{
        self.canChangenum = 1;
        if (self.xiaoliangPaiXuBOOL == YES) {
            // 销量递增
            [self.XiaoLiangBtn setImage:[UIImage imageNamed:@"sysicon_n_17"] forState:UIControlStateNormal];
        }else{
            // 销量递减
            [self.XiaoLiangBtn setImage:[UIImage imageNamed:@"changeXia"] forState:UIControlStateNormal];
        }

    }
}


- (void)priceListAction:(UIButton *)sender{
    // 价格排序
    [self.ShaiXuanBtn setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    [self.XiaoLiangBtn setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    [self.priceBtn setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
    
    [self.XiaoLiangBtn setImage:[UIImage imageNamed:@"sysicon_n_18"] forState:UIControlStateNormal];

    if (self.canChangenum == 2) {
        [self.priceBtn setImage:[UIImage imageNamed:@"sysicon_n_18"] forState:UIControlStateNormal];
        
        if (self.jiagePaiXuliangBOOL == YES) {
            // 价格递减
            [self.priceBtn setImage:[UIImage imageNamed:@"changeXia"] forState:UIControlStateNormal];
            self.jiagePaiXuliangBOOL = NO;
        }else{
            // 价格递增
            [self.priceBtn setImage:[UIImage imageNamed:@"sysicon_n_17"] forState:UIControlStateNormal];
            self.jiagePaiXuliangBOOL = YES;
        }
    }else{
        self.canChangenum = 2;
        if (self.jiagePaiXuliangBOOL == YES) {
            // 价格递增
            [self.priceBtn setImage:[UIImage imageNamed:@"sysicon_n_17"] forState:UIControlStateNormal];
        }else{
            // 价格递减
            [self.priceBtn setImage:[UIImage imageNamed:@"changeXia"] forState:UIControlStateNormal];
        }
        
    }
    
    
    
}




- (void)ShopDetailAction:(UIButton *)sender{
    // 店铺详情
    if (self.scrollViewBack.contentOffset.x != ZTY_SCREEN_WIDTH *2) {
        [self.scrollViewBack setContentOffset:CGPointMake(ZTY_SCREEN_WIDTH * 2, 0)animated:YES];
        [self.scrollViewTop setContentOffset:CGPointMake(ZTY_SCREEN_WIDTH/3 * 2, 0)animated:YES];
    }
    [self.allButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    [self.ShopDetailButton setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
    [self.ShopManagerButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
}

- (void)ShopManagerAction:(UIButton *)sender{
    // 店长推荐
    if (self.scrollViewBack.contentOffset.x != ZTY_SCREEN_WIDTH) {
        [self.scrollViewBack setContentOffset:CGPointMake(ZTY_SCREEN_WIDTH, 0)animated:YES];
        [self.scrollViewTop setContentOffset:CGPointMake(ZTY_SCREEN_WIDTH/3, 0)animated:YES];
    }
    [self.allButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    [self.ShopDetailButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    [self.ShopManagerButton setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
}

- (void)allAction:(UIButton *)sender{
    // 所有商品
    [self.allButton setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
    [self.ShopDetailButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    [self.ShopManagerButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
    
    [self.scrollViewBack setContentOffset:CGPointMake(0, 0)animated:YES];
    [self.scrollViewTop setContentOffset:CGPointMake(0, 0)animated:YES];
}

#pragma mark - tableview delegate & datasource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.allListArr.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.backgroundColor = [UIColor getColorFromRGBString:@"#F9F9F9"];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }
    cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
    cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:236/255.0 green:237/255.0 blue:239/255.0 alpha:1];
    if (indexPath.row == 2) {
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.textLabel.textColor = [UIColor getColorFromRGBString:@"F48000"];
    }else{
        cell.textLabel.textColor = [UIColor colorWithRed:84/255.0 green:84/255.0 blue:84/255.0 alpha:1];
    }
    
    
    cell.textLabel.text = self.allListArr[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


#pragma mark - CollectionViewDelegate And DataSource


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"section, : %lu, item:%ld",indexPath.section, indexPath.item);
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 100;
}



- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ShopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"item" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}





#pragma mark - LazyLoad

- (UIView *)topView{
    if (_topView == nil) {
        _topView = [[UIView alloc]init];
        _topView.backgroundColor = [UIColor getColorFromRGBString:@"#F48000"];
    }
    return _topView;
}

- (UIButton *)ShopDetailButton{
    if (_ShopDetailButton == nil) {
        _ShopDetailButton = [[UIButton alloc]init];
        _ShopDetailButton.backgroundColor = [UIColor whiteColor];
        [_ShopDetailButton setTitle:@"店铺详情" forState:UIControlStateNormal];
        [_ShopDetailButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
        [_ShopDetailButton addTarget:self action:@selector(ShopDetailAction:) forControlEvents:UIControlEventTouchUpInside];
        _ShopDetailButton.font = [UIFont systemFontOfSize:15];
    }
    return _ShopDetailButton;
}

- (UIButton *)ShopManagerButton{
    if (_ShopManagerButton == nil) {
        _ShopManagerButton = [[UIButton alloc]init];
        _ShopManagerButton.backgroundColor = [UIColor whiteColor];
        [_ShopManagerButton setTitle:@"店长推荐" forState:UIControlStateNormal];
        [_ShopManagerButton setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
        [_ShopManagerButton addTarget:self action:@selector(ShopManagerAction:) forControlEvents:UIControlEventTouchUpInside];
        _ShopManagerButton.font = [UIFont systemFontOfSize:15];
    }
    return _ShopManagerButton;
}

- (UIButton *)allButton{
    if (_allButton == nil) {
        _allButton = [[UIButton alloc]init];
        _allButton.backgroundColor = [UIColor whiteColor];
        [_allButton setTitle:@"全部商品" forState:UIControlStateNormal];
        [_allButton setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
        [_allButton addTarget:self action:@selector(allAction:) forControlEvents:UIControlEventTouchUpInside];
        _allButton.font = [UIFont systemFontOfSize:15];
    }
    return _allButton;
}

- (UIScrollView *)scrollViewBack{
    if (_scrollViewBack == nil) {
        _scrollViewBack = [[UIScrollView alloc]init];
        
        _scrollViewBack.backgroundColor = [UIColor getColorFromRGBString:@"#F2F2F2"];
        _scrollViewBack.delegate = self;
        _scrollViewBack.contentSize = CGSizeMake(ZTY_SCREEN_WIDTH * 3, 0);
        _scrollViewBack.pagingEnabled = YES;
        _scrollViewBack.bounces = NO;
    }
    return _scrollViewBack;
}

- (UIScrollView *)scrollViewTop{
    if (_scrollViewTop == nil) {
        _scrollViewTop = [[UIScrollView alloc]init];
        _scrollViewTop.contentSize = CGSizeMake(0 , 0);
        _scrollViewTop.bounces = NO;
        _scrollViewTop.showsHorizontalScrollIndicator = NO;
    }
    return _scrollViewTop;
}

- (UITableView *)mytableView{
    if (_mytableView == nil) {
        _mytableView = [[UITableView alloc]init];
        _mytableView.delegate = self;
        _mytableView.dataSource = self;
    }
    return _mytableView;
}

- (NSArray *)allListArr{
    if (_allListArr == nil) {
        _allListArr = @[@"家具清洁",@"休闲零食",@"全部",@"儿童食品",@"糖果巧克力",@"饮料饮品",@"营养冲剂",@"酒水",@"粮油干货",@"休闲娱乐"];
    }
    return _allListArr;
}


- (UIView *)collectionBackView{
    if (_collectionBackView == nil) {
        _collectionBackView = [[UIView alloc]init];
        _collectionBackView.backgroundColor = [UIColor whiteColor];
        
    }
    return _collectionBackView;
}

- (UIButton *)priceBtn{
    if (_priceBtn == nil) {
        _priceBtn = [[UIButton alloc]init];
        _priceBtn.backgroundColor = [UIColor whiteColor];
        [_priceBtn setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
        [_priceBtn addTarget:self action:@selector(priceListAction:) forControlEvents:UIControlEventTouchUpInside];
        _priceBtn.font = [UIFont systemFontOfSize:13];
        [_priceBtn setTitle:@"价格" forState:UIControlStateNormal];
        [_priceBtn setImage:[UIImage imageNamed:@"sysicon_n_18"] forState:UIControlStateNormal];
        
    }
    return _priceBtn;
}

- (UIButton *)XiaoLiangBtn{
    if (_XiaoLiangBtn == nil) {
        _XiaoLiangBtn = [[UIButton alloc]init];
        _XiaoLiangBtn.backgroundColor = [UIColor whiteColor];
        [_XiaoLiangBtn setTitleColor:[UIColor getColorFromRGBString:@"F48000"] forState:UIControlStateNormal];
        _XiaoLiangBtn.font = [UIFont systemFontOfSize:13];
        [_XiaoLiangBtn addTarget:self action:@selector(XiaoLiangBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [_XiaoLiangBtn setTitle:@"销量" forState:UIControlStateNormal];
        [_XiaoLiangBtn setImage:[UIImage imageNamed:@"sysicon_n_17"] forState:UIControlStateNormal];
    }
    return _XiaoLiangBtn;
}

- (UIButton *)ShaiXuanBtn{
    if (_ShaiXuanBtn == nil) {
        _ShaiXuanBtn = [[UIButton alloc]init];
        _ShaiXuanBtn.backgroundColor = [UIColor whiteColor];
        [_ShaiXuanBtn setTitleColor:[UIColor getColorFromRGBString:@"909090"] forState:UIControlStateNormal];
        _ShaiXuanBtn.font = [UIFont systemFontOfSize:13];
        [_ShaiXuanBtn addTarget:self action:@selector(ShaiXuanBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [_ShaiXuanBtn setTitle:@"筛选" forState:UIControlStateNormal];
    }
    return _ShaiXuanBtn;
}

- (UICollectionViewFlowLayout *)layout{
    if (_layout == nil) {
        _layout = [[UICollectionViewFlowLayout alloc]init];
        _layout.itemSize =CGSizeMake((ZTY_SCREEN_WIDTH - 12) /3, 160);
        // 滚动方向
        _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        //  section边距
        _layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
        // item 边距
        
        // 列间距
        _layout.minimumInteritemSpacing = 1;
        // 行间距
        _layout.minimumLineSpacing = 10;
        //
        _layout.headerReferenceSize = CGSizeMake(self.view.frame.size.width, 0);

    }
    return _layout;
}

- (UICollectionView *)myCollectionView{
    if (_myCollectionView == nil) {
        _myCollectionView = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:self.layout];
        _myCollectionView.delegate = self;
        _myCollectionView.dataSource = self;
//        _myCollectionView.contentInset = UIEdgeInsetsMake(2, 0, 2, 0);
        [_myCollectionView registerClass:[ShopCollectionViewCell class] forCellWithReuseIdentifier:@"item"];
        
        _myCollectionView.backgroundColor = [UIColor getColorFromRGBString:@"F2F2F2"];

    }
    return _myCollectionView;
}


- (UILabel *)topLableTitle{
    if (_topLableTitle == nil) {
        _topLableTitle = [[UILabel alloc]init];
        _topLableTitle.text =  @"起价¥30|送达30分钟|营业时间: 08:14 - 23:00";
        _topLableTitle.font = [UIFont systemFontOfSize:12];
        _topLableTitle.textColor = [UIColor whiteColor];
        _topLableTitle.adjustsFontSizeToFitWidth = YES;
        
    }
    return _topLableTitle;
}

- (UILabel *)topLableDetail{
    if (_topLableDetail == nil) {
        _topLableDetail = [[UILabel alloc]init];
        _topLableDetail.text = @"      您好欢迎光临青年汇便利店 本店营业时间为";
        _topLableDetail.textColor = [UIColor whiteColor];
        _topLableDetail.backgroundColor = [UIColor getColorFromRGBString:@"#E17601"];
        _topLableDetail.font = [UIFont systemFontOfSize:12];
    }
    return _topLableDetail;
}

- (UIImageView *)topImageViewJianTou{
    if (_topImageViewJianTou == nil) {
        _topImageViewJianTou = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sysicon_n_66"]];
    }
    return _topImageViewJianTou;
}

- (UIImageView *)topImageViewLaba{
    if (_topImageViewLaba == nil) {
        _topImageViewLaba = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
    }
    return _topImageViewLaba;
}

- (UIImageView *)topImageViewPhoto{
    if (_topImageViewPhoto == nil) {
        _topImageViewPhoto = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"user_pic_11"]];
    }
    return _topImageViewPhoto;
}

- (UIImageView *)shaiXuanImageView{
    if (_shaiXuanImageView == nil) {
        _shaiXuanImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sysicon_n_16"]];
    }
    return _shaiXuanImageView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
